package com.example.rpapp.assembler;


import com.example.rpclient.dto.RuleAddCmd;
import com.example.rpclient.dto.RuleUpdateCmd;
import com.example.rpclient.dto.data.RuleVo;
import com.example.rpdomain.rule.MinNumber;
import com.example.rpdomain.rule.RuleEntity;

import java.time.LocalDateTime;


public class RuleAssembler {
    public static RuleEntity toAddEntity(RuleAddCmd cmd) {
        RuleEntity ruleEntity = new RuleEntity();
        ruleEntity.setRuleName(cmd.getRuleName());
        ruleEntity.setMaxJoinNumber(new MinNumber(cmd.getMaxJoinNumber()));
        ruleEntity.setMaxWinningNumber(new MinNumber(cmd.getMaxWinningNumber()));
        ruleEntity.setCreateTime(LocalDateTime.now());
        ruleEntity.setCreator("大帅哥");
        ruleEntity.setUpdateTime(LocalDateTime.now());
        ruleEntity.setUpdater("大帅哥");

        return ruleEntity;
    }

    public static RuleVo toRuleVO(RuleEntity entity) {
        RuleVo ruleVO = new RuleVo();
        ruleVO.setId(entity.getId());
        ruleVO.setRuleName(entity.getRuleName());
        ruleVO.setMaxJoinNumber(entity.getMaxJoinNumber().getNumber());
        ruleVO.setMaxWinningNumber(entity.getMaxWinningNumber().getNumber());
        ruleVO.setCreateTime(entity.getCreateTime());
        ruleVO.setCreator("大帅哥");
        ruleVO.setUpdateTime(entity.getUpdateTime());
        ruleVO.setUpdater("大帅哥");

        return ruleVO;
    }

    public static RuleEntity toUpdateEntity(RuleUpdateCmd cmd) {
        RuleEntity ruleEntity = new RuleEntity();
        ruleEntity.setId(cmd.getId());
        ruleEntity.setRuleName(cmd.getRuleName());
        ruleEntity.setMaxJoinNumber(new MinNumber(cmd.getMaxJoinNumber()));
        ruleEntity.setMaxWinningNumber(new MinNumber(cmd.getMaxWinningNumber()));
        ruleEntity.setUpdateTime(LocalDateTime.now());
        ruleEntity.setUpdater("大帅哥");

        return ruleEntity;
    }
}
